﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Gmantis.Controls
{
    public class ProjectThicknessConverter : IValueConverter
    {
        object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Thickness thickness = (Thickness)value;
            List<string> list = new List<string>(((string)parameter).ToLower().Split(new char[] { '-' }));
            double num = 1.0;
            foreach (string str in list)
            {
                if (str.StartsWith("ratio:"))
                {
                    num = double.Parse(str.Substring(6), CultureInfo.InvariantCulture);
                }
            }
            if (list.Contains("negate"))
            {
                num = -num;
            }
            if (list.Contains("left"))
            {
                return (thickness.Left * num);
            }
            if (list.Contains("top"))
            {
                return (thickness.Top * num);
            }
            if (list.Contains("right"))
            {
                return (thickness.Right * num);
            }
            if (!list.Contains("bottom"))
            {
                throw new ArgumentException();
            }
            return (thickness.Bottom * num);
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
